Shader "Oven/MixerShader" {
Properties {
	_MainTex ("Base (RGB) Trans (A)", 2D) = "black" {}    
    _Centralization ("Centralization Strength", Float) = 1.0
}

SubShader {
	Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
	LOD 100
	
	ZWrite Off
	Blend SrcAlpha OneMinusSrcAlpha 
    Blendop Max
	
	Pass {  
		CGPROGRAM
			#pragma vertex vert
			#pragma fragment frag
			
			#include "UnityCG.cginc"

			struct appdata_t {
				float4 vertex : POSITION;
				float2 texcoord : TEXCOORD0;
			};

			struct v2f {
				float4 vertex : SV_POSITION;
				half2 texcoord : TEXCOORD0;
			};

			sampler2D _MainTex;
			float4 _MainTex_ST;
            float _Centralization;
			
			v2f vert (appdata_t v)
			{
				v2f o;
				o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
				o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex);
				return o;
			}
			
			fixed4 frag (v2f i) : SV_Target
			{                
				fixed4 col = tex2D(_MainTex, i.texcoord);
               
                //Offset from texture center
                float2 offset = i.texcoord - float2(0.5, 0.5);

                //lower strength based on distance from center but just a little bit                
                float sqOffset = max( length(offset.x), length(offset.y));

                //decreasing defines how big part will get strenght lowered below 1. Eg decreasing 3 means about 1/3 of the texture radius will be decreasing
                //centralization paramter allows to define strength of this modifier from square to horizontal only.  Rivers would mix themselves along one axis only
                float decreasing = 3;
                float strength = min(1, decreasing*(1 - sqOffset*2))* _Centralization + 
                                 min(1, decreasing*(1 - length(offset.x)*2))* (1 - _Centralization); 
                
                //Below are 2 blending styles. First prefer clean blending only on influence level
                // while other will normalize two to stong influences (lowering fight area) second is prefered if first builds to sharp edges streaching textures 
                // or simply you are not fun of the shape it produces. 
                //To use one or the other simply commend our one you don't like
                
                //Blending style 1
                col.a *= strength;

                //Blending style 2
                //col *= strength;

				return col;
			}
		ENDCG
	}
}

}
